<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    request.setAttribute("basePath", basePath);
%>
<%@ include file="/resources/js/easyui/taglibs.jsp" %>
<%@ include file="/resources/js/wechat/_wechatui.jsp" %>
<%@ include file="/resources/js/easyui/_viewJS.jsp" %>
<!DOCTYPE>
<html>
<head>
    <title>更换手机号</title>
</head>
<body>
<div class="loading"></div>
<!-- header -->
<header>
    <a href="javascript:history.go(-1);" class="top_fh">更换手机号</a>
</header>
<!-- header end -->

<div class="page nb_page">
    <div class="my_ghsjinner">
        <ul>
            <li class='ico_ghsj'>
            <div><input id="newmoblie" type="text" placeholder="请输入新手机号码"></div>
            </li>
            <li><i class="newmobliepoint">*手机号码不能为空</i></li>
            <li class='get_yzm'>
                <div>
                    <input id="mobliecode" type="text" placeholder="请输入验证码"><a id="getMoblieCode" href="JavaScript:;">获取验证码</a>
                </div>
            </li>
            <li><i class="newmobliecodepoint">*验证码不能为空</i></li>
        </ul>
        <div class="my_qrbutton"><a id="changeMoblie" href="javascript:void(0);" class='cur' >确认</a></div>
    </div>
</div>

</body>
</html>
<script>
    $("#newmoblie, #mobliecode").on("focus", function(){     /*得到焦点*/
        $("#newmoblie, #mobliecode").parent().parent().next().children().removeClass("cur");
    });

    var regTel=/^1[34578]\d{9}$/;
    var newmoblie="";
    var getCaptcha = $("#getMoblieCode").click(function (){
        newmoblie = $("#newmoblie").val();
        if (typeof(newmoblie) == "undefined" || newmoblie.length == 0) {
            $(".newmobliepoint").text("*手机号码不能为空").addClass("cur");
            //alert('温馨提示:请输入您的手机号码');
        }else if(regTel.test(newmoblie)){
            if(!$(this).hasClass('cur')){
                $(this).addClass('cur').text('重新发送（60s）');
                yzsetTime($(this));
                $(this).unbind("click");
            }
            $.ajax({
                url: '${basePath}sms/sendMobileCode',
                type: 'POST',
                error: function (response) {
                    ViewHelper.func.ajaxWechatErrorMessage(response);
                },
                success: function (ret) {
                    console.log(ret);
                    if (ret.result) {
                        alert('温馨提示:' + ret.info);
                    } else {
                        alert('提示:保存失败!');
                    }
                }
            });
        }else{
            $(".newmobliepoint").text("*手机号格式错误").addClass("cur");
            //alert("手机号格式错误");
        }
    });
    var setTime=0;
    function yzsetTime($index){
        var yzSet=window.setInterval(function(){
            setTime++;
            if(setTime==60){
                setTime=0;
                $($index).removeClass('cur').text('获取验证码');
                clearInterval(yzSet);
                getCaptcha();
            }else{
                $($index).text('重新发送（'+ (60-setTime) +'s）');
            }
        },1000);
    };
    // getCaptcha();

    $("#changeMoblie").click(function () {
        var moblie = $("#newmoblie").val();
        var mobliecode = $("#mobliecode").val();

        if (typeof(moblie) == "undefined" || moblie.length == 0){
            $(".newmobliepoint").text("*手机号码不能为空").addClass("cur");
            //alert('温馨提示:请输入您的手机号码');
        }else if(!regTel.test(moblie)){
            $(".newmobliepoint").text("*手机号格式错误").addClass("cur");

        }else if (typeof(mobliecode) == "undefined" || mobliecode.length == 0){
            $(".newmobliecodepoint").text("*验证码不能为空").addClass("cur");
            //alert('温馨提示:请输入短信验证码');
        } else if(regTel.test(moblie) && mobliecode!=""){

            $.ajax({
                url: '${basePath}wechat/indivdual/changeMoblie',
                type: 'POST',
                data: {"code":mobliecode ,"moblie": moblie},
                error: function (response) {
                    ViewHelper.func.ajaxWechatErrorMessage(response);
                },
                success: function (ret) {
                    $("#mobliecode").addClass('cur');
                    if (ret.result) {
                        alert('温馨提示:' + ret.info);
                        window.location.href = '${basePath}wechat/indivdual/showseurity';
                    } else {
                        alert(ret.info);
                    }

                }
            });
        }
    });

   /* $("#getMoblieCode").click(function () {
        var newmoblie = $("#newmoblie").val();
        if (typeof(newmoblie) == "undefined" || newmoblie.length == 0) {
            alert('温馨提示:请输入您的手机号码');
        } else {
            $.ajax({
                url: '${basePath}sms/sendMobileCode',
                type: 'POST',
                error: function (response) {
                    ViewHelper.func.ajaxWechatErrorMessage(response);
                },
                success: function (ret) {
                    console.log(ret);
                    if (ret.result) {
                        alert('温馨提示:' + ret.info);
                    } else {
                        alert('提示:保存失败!');
                    }
                }
            });
        }
    });

    $("#changeMoblie").click(function () {
        var moblie = $("#newmoblie").val();
        var mobliecode = $("#mobliecode").val();

        if (typeof(moblie) == "undefined" || moblie.length == 0) {
            alert('温馨提示:请输入您的手机号码');
        } else if (typeof(mobliecode) == "undefined" || mobliecode.length == 0) {
            alert('温馨提示:请输入短信验证码');
        } else {
            $.ajax({
                url: '${basePath}wechat/indivdual/changeMoblie',
                type: 'POST',
                data: {"code":mobliecode ,"moblie": moblie},
                error: function (response) {
                    ViewHelper.func.ajaxWechatErrorMessage(response);
                },
                success: function (ret) {
                    if (ret.result) {
                        alert('温馨提示:' + ret.info);
                        window.location.href = '${basePath}wechat/indivdual/showseurity';
                    } else {
                        alert(ret.info);
                    }

                }
            });
        }
    })
    ;*/

</script>